package com.tool.weixin.message;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import com.tool.weixin.message.type.RespType;
import com.tool.weixin.util.MessageUtil;

/**
 * 图片消息
 * @author huff
 *
 */
public class ImageMessage extends BaseMessage {

	private Media Image;
	
	public ImageMessage(String MediaId) {
		Image = new Media();
		Image.setMediaId(MediaId);
	}
	
	public ImageMessage(String touser,String MediaId) {
		this.FromUserName = touser;
		Image = new Media();
		Image.setMediaId(MediaId);
	}

	public Media getMedia() {
		return Image;
	}

	public void setMedia(Media media) {
		this.Image = media;
	}
	
	@Override
	public String toxml() {
		super.toxml();
		this.setMsgType(RespType.IMAGE);
		return MessageUtil.imageMessageToXml(this);
	}
	
	@Override
	public String tojson() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("touser", this.getFromUserName());
		map.put("msgtype", RespType.IMAGE);
		Map<String, Object> image = new HashMap<String, Object>();
		image.put("media_id", this.getMedia().getMediaId());
		map.put("image", image);
		return JSONObject.fromObject(map).toString();
	}
}
